package j2025.j03;

/**
 * @Author 猫大仙
 */
public class j0325 {
    public TreeNode invertTree(TreeNode root) {
        if(root == null) return null;
        TreeNode tmp = root.left;
        root.left = root.right;
        root.right = tmp;
        invertTree(root.left);
        invertTree(root.right);
        return root;
    }

    public boolean isSymmetric(TreeNode root) {
        if(root==null) return true;
        return check(root.left,root.right);
    }
    public boolean check(TreeNode left,TreeNode right){
        if(left == null && right == null) return true;
        if((left==null && right!=null) || (left!=null && right==null)) return false;
        if(left.val != right.val) return false;
        return check(left.left,right.right) && check(left.right,right.left);
    }
}
